Nail = class(AdvancedObjectCreater)

function Nail:init(id,name,tex,icon)
    AdvancedObjectCreater.init(self,id,name,tex,icon)
end

function Nail:createTouch(touch)
    if touch.state ~= BEGAN then return false end
    
    local nail = {}
    self:startCreating(nail)
    
    local pos = vec2(touch.x,touch.y)
    for k,body in pairs(game.world.objects) do
        if body.testPoint and body:testPoint(pos) then
            if body.id == self.id then return true end
            local nailPos = body:getLocalPoint(pos)
            nail.x = nailPos.x
            nail.y = nailPos.y
            nail.angle = 0
            nail.tex = self.tex
            nail.id = self.id
            nail.name = self.name
            
            nail.fatherObject = body
            body:addChildObject(nail)
            
            nail.draw = self.draw
            nail.touched = self.touched
            game.world:addObject(nail)
            return true
        end
    end
    return false
end

function Nail:draw()
    pushMatrix()
    translate(self.fatherObject.x, self.fatherObject.y)
    rotate(self.fatherObject.angle)
    rotate(self.angle)
    sprite(self.tex,self.x,self.y)
    popMatrix()
end

function Nail:touched(touch)
    
end